angular.module("controller.cashback", ["services"])
	.controller("cashbackCtrl", ["$scope", "apiService", "alertManager", function($scope, apiService, alertManager) {
		$scope.data = {};
		$scope.data.cashback = {
				percentageForCustomer: 0,
				percentageForRecommender: 0,
				percentageForManager: 0 };
		function getCashback() {
			apiService.getDefaultCashback().then(function(data) {
				$scope.data.cashback = data;
			}, function(response) {
				console.log(response);
				alertManager.addAlert("danger", "無法獲取返現策略");
			});
		}
		getCashback();
		$scope.data.saveCashback = function() {
			apiService.saveDefaultCashback($scope.data.cashback).then(function(data) {
				alertManager.addAlert("success", "成功保存返現策略");
			}, function() {
				alertManager.addAlert("danger", "無法保存返現策略");
			});
		};
	}])